﻿using System.Windows.Forms;
using Finance.Properties;
using Finance.ViewModels;

namespace Finance.Views
{
	internal partial class DebtDocumentControl : UserControl
	{
		public DebtDocumentControl()
		{
			InitializeComponent();
			label1.Text = Resources.DebtDocumentControl_CommentsLabel;
			_rateLabel.Text = Resources.DebtDocumentControl_InterestRateLabel;
		}

		private DebtDocumentViewModel _viewModel;

		public DebtDocumentViewModel ViewModel
		{
			set
			{
				_documentBaseControl.ViewModel = value;

				if (value == null || value == _viewModel)
					return;

                _viewModel = value;
                
				_textBoxDescription.DataBindings.Add(
					new Binding("Text", _viewModel, "Description", true, DataSourceUpdateMode.OnValidation));

				_rateTextBox.DataBindings.Add(
					new Binding("Text", _viewModel, "PercentRate", true, DataSourceUpdateMode.OnValidation));
			}
		}

		public bool Apply()
		{
			return _documentBaseControl.Apply();
		}
	}
}
